home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: floats in borland C++ 4.5
- Date: Sun, 17 Mar 96 18:19:20 GMT
- Organization: none
- Message-ID: <827086760snz@genesis.demon.co.uk>
- References: <4if2ec$scg@bertrand.ccs.carleton.ca>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4if2ec$scg@bertrand.ccs.carleton.ca>
- abelo@chat.carleton.ca "Andrew Belo" writes:
-
- >
- >When ever I write a program that uses float or doubles I get errors such
- >as floating point library not linked or stack fault. These errors do not
- >happen when I am compiling my files the happen when I am actualy running
- >the program! I will post some code to give you an example. WHen running
- >this code it gives the following message
- >Floating point error: Stack
- >fault. Abnormal termination.
- >
- > when this function is called:
- >
- >void bubblesort( double *dblarray, int numberOfElements)
- >
- >{
- > int top, search, temp;
- >
- > for( top = 0; top < numberOfElements -1; top++)
- > for(search = top +1; search < numberOfElements; search++)
- > if(dblarray[search] > dblarray[top])
- > {
- > temp = dblarray[search];
- > dblarray[search] = dblarray[top];
- > dblarray[top] = temp;
- > }
- >}
-
- Firstly this isn't a bubble sort (e.g. bubble sort always compares and swaps
- adjacent elements), it is an exchange sort. Do you have any reason not to
- use the standard library qsort() function - it is likely to be much more
- efficient.
-
- In the code you are trying to exchange double quantities using an int
- temporary variable - make temp a double.
-
- For 'floating point library not linked' or similar see the FAQ (which
- actually directs you to the comp.os.msdos.progarmmer FAQ in this case).
-
- There is nothing else obviously wrong however the problem may be in how you
- call it. Post a minimal but *complete* program (i.e. one that we can
- compile and execute) demonstrating the problem.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-